package com.beyondsoft.common.core.sys.initialization;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MQ 队列配置
 */
@Configuration
public class RabbitConfig {

    public final static String STATE_QUEUE = "sub.state";

    public final static String FANOUT_TEST_QUEUE = "fanout.TEST";

    public final static String FANOUT_USERS_QUEUE = "fanout.USERS";

    public final static String FANOUT_EXCHANGE = "fanoutExchange";

    @Bean
    public Queue stateQueue() {
        return new Queue(RabbitConfig.STATE_QUEUE);
    }

    @Bean
    public Queue testMessage() {
        return new Queue(RabbitConfig.FANOUT_TEST_QUEUE);
    }

    @Bean
    public Queue usersMessage() {
        return new Queue(RabbitConfig.FANOUT_USERS_QUEUE);
    }

    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange(RabbitConfig.FANOUT_EXCHANGE);
    }

    @Bean
    Binding bindingExchangeTEST(Queue testMessage, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(testMessage).to(fanoutExchange);
    }

    @Bean
    Binding bindingExchangeUSERS(Queue usersMessage, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(usersMessage).to(fanoutExchange);
    }

}
